﻿using MasterDetailTemplate.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace MasterDetailTemplate.Services.Implementations
{
    public class HistoryTodayService : IHistoryTodayService
    {
        /// <summary>  
        /// 获取历史上的今天  
        /// </summary>  
        /// <returns></returns>  
        public async Task<IList<HistoryToday>> GetTodayAsync()
        {
            DateTime dt = DateTime.Now;
            string today = dt.Month.ToString() + dt.Day.ToString();
            Uri historytodayUri =
            new Uri("https://zhufred.gitee.io/zreader/ht/event/" + today +
            ".json");

            var httpClient = new HttpClient();
            var response = await httpClient.GetAsync(historytodayUri);
            var json = await response.Content.ReadAsStringAsync();

            return JsonConvert.DeserializeObject<IList<HistoryToday>>(json);
        }

    }
}
